home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / dictiona.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.5 KB  |  80 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  dictionary.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17.  
  18. //------------------------------------------------------------------------------
  19. //
  20. // dictionary  (data structure: red black trees)
  21. //
  22. // Stefan Naeher (1989)
  23. //
  24. //------------------------------------------------------------------------------
  25.  
  26. #ifndef DICTIONARYH
  27. #define DICTIONARYH
  28.  
  29. #ifndef RBTREEH
  30. #include <LEDA/rb_tree.h>
  31. #endif
  32.  
  33. typedef rb_tree_node* dic_item;
  34.  
  35. #define dictionary(keytype,infotype) name3(keytype,infotype,dictionary)
  36.  
  37.  
  38. #define dictionarydeclare2(keytype,infotype)\
  39. \
  40. struct dictionary(keytype,infotype) : public rb_tree {\
  41. \
  42. int  cmp(ent& x, ent& y) const { return compare(*(keytype*)&x,*(keytype*)&y); }\
  43. void clear_key(ent& x)   const { Clear(*(keytype*)&x); }\
  44. void clear_inf(ent& x)   const { Clear(*(infotype*)&x); }\
  45. void copy_key(ent& x)    const { Copy(*(keytype*)&x); }\
  46. void copy_inf(ent& x)    const { Copy(*(infotype*)&x); }\
  47. \
  48. int       defined(keytype y) const { return rb_tree::member(Ent(y)); }\
  49. dic_item  lookup(keytype y)  const { return rb_tree::lookup(Ent(y)); }\
  50. infotype& info(dic_item it)     { return *(infotype*)&(rb_tree::info(it)); } \
  51. void      change_inf(dic_item it, infotype i) { info(it) = i; }\
  52. \
  53. dic_item  insert(keytype y,infotype x)\
  54.                                 { return rb_tree::insert(Ent(y),Ent(x)); } \
  55. \
  56. void      del(keytype y)         { rb_tree::del(Ent(y)); } \
  57. void      del_item(dic_item it)  { del(key(it)); } \
  58. keytype   key(dic_item it)  const { return keytype(rb_tree::key(it)); }\
  59. infotype  inf(dic_item it)  const { return infotype(rb_tree::info(it)); } \
  60. infotype  access(keytype k) const { return inf(lookup(k));}\
  61. \
  62. dictionary(keytype,infotype)& operator =(const dictionary(keytype,infotype)& D)\
  63. { return (dictionary(keytype,infotype)&)rb_tree::operator=(rb_tree((rb_tree&) D)); }\
  64. \
  65.  dictionary(keytype,infotype)()   {}\
  66.  dictionary(keytype,infotype)(const dictionary(keytype,infotype)& D) :\
  67.   rb_tree((rb_tree&) D)   {}\
  68. ~dictionary(keytype,infotype)()   { clear(); }\
  69. } ;
  70.  
  71.  
  72. // ----------------------------------------------------------------
  73. // iteration
  74. // ----------------------------------------------------------------
  75.  
  76. #define forall_dic_items(i,D) for(i = (D).first_item(); i; i=(D).next_item(i))
  77.  
  78. #endif
  79.